//
//  fitstCellTableViewCell.m
//  1243
//
//  Created by 袖手旁觀 on 16/4/7.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "fitstCellTableViewCell.h"

@implementation fitstCellTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    [self addAndSetUpCellUI];
    
    return [super initWithStyle:style reuseIdentifier:reuseIdentifier];
}

- (void)addAndSetUpCellUI {
    self.firstCellLabel = [[UILabel alloc] init];
    
    self.timeCellLabel = [[UILabel alloc] init];
    self.timeCellLabel.textAlignment = NSTextAlignmentCenter;
    self.timeCellLabel.font = [UIFont systemFontOfSize:9];
    self.timeCellLabel.numberOfLines = 0;
    self.timeCellLabel.textColor = [UIColor lightGrayColor];
    
    self.buttonArray = [[UIView alloc] init];
    
    self.nameLabel = [[UILabel alloc] init];
//    self.nameLabel.backgroundColor = [UIColor orangeColor];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.font = [UIFont systemFontOfSize:13];
//    [self.buttonArray addSubview:self.firstCellLabel];
//    [self.buttonArray addSubview:self.timeCellLabel];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat cellWidth = WIDTH / 8;
    
    [self.firstCellLabel setFrame:CGRectMake(0, 5, cellWidth, 30)];
    [self.timeCellLabel setFrame:CGRectMake(cellWidth, 5, cellWidth, 25)];
    [self.nameLabel setFrame:CGRectMake(cellWidth * 2, 5, cellWidth, 30)];
    [self.buttonArray setFrame:CGRectMake(0, 0, WIDTH, 40)];
    
    for (int j = 0;j < self.cellDataArray.count;j++) {
        for (int i = 0;i < 5;i++) {
            if (i >= self.cellButtonCount) {
                break;
            }
            
            CGFloat cellButtonX = (cellWidth * 3) + i * cellWidth;
            CGFloat margin = (WIDTH / 8 - 30) / 2;
            UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(cellButtonX + margin, 5, 30, 30)];
            
            cellLabel.textColor = [UIColor blackColor];
            [cellLabel setBackgroundColor:[UIColor colorWithRed:213 / 255.0 green:213 / 255.0 blue:213 / 255.0 alpha:1]];
            
            if (i < self.changeCellColor) {
                [cellLabel setBackgroundColor:[UIColor colorWithRed:47 / 255.0 green: 177 / 255.0 blue:70 / 255.0 alpha:1]];
                cellLabel.textColor = [UIColor whiteColor];
            }
            
            if (i < self.changeCellColor && self.isCellColor) {
                [cellLabel setBackgroundColor:[UIColor colorWithRed:47 / 255.0 green: 177 / 255.0 blue:70 / 255.0 alpha:1]];
                cellLabel.textColor = [UIColor whiteColor];
            } else {
                self.isCellColor = NO;
            }
            
            cellLabel.text = self.cellDataArray[j][i];
            cellLabel.textAlignment = NSTextAlignmentCenter;
            
            cellLabel.font = [UIFont systemFontOfSize:11];
            cellLabel.layer.cornerRadius = 15;
            cellLabel.layer.masksToBounds = YES;
            cellLabel.textAlignment = NSTextAlignmentCenter;
            [self.buttonArray addSubview:cellLabel];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
